package org.deadline.model.user;

import flexjson.JSONDeserializer;
import flexjson.JSONSerializer;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.deadline.model.baseapp.BaseEntity;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;

@Entity
public class SystemMailMessage extends BaseEntity  implements Serializable {

    @NotNull
    @Size(min = 6, max = 15)
    private String subject;

    @NotNull
    @Size(min = 6, max = 15)
    private String body;

    @NotNull
    @Size(min = 6, max = 15)
    private String messageType;

    @NotNull
    @ManyToOne
    private Person sender;

    @NotNull
    @Size(min = 6, max = 15)
    private String recipientTo;

    @NotNull
    @Size(min = 6, max = 15)
    private String recipientCC;

	@Id
	@Column(name="id",unique=true,nullable=false)
	@SequenceGenerator(name="system_mail_message_seq_gen",sequenceName="system_mail_message_seq")
	@GeneratedValue(generator="system_mail_message_seq_gen",strategy=GenerationType.TABLE)
	@Generated(GenerationTime.INSERT)
	private Long id;

	
	public String toJson() {
        return new JSONSerializer().exclude("*.class").deepSerialize(this);
    }

	public static SystemMailMessage fromJsonToSystemMailMessage(String json) {
        return new JSONDeserializer<SystemMailMessage>().use(null, SystemMailMessage.class).deserialize(json);
    }

	public static String toJsonArray(Collection<SystemMailMessage> collection) {
        return new JSONSerializer().exclude("*.class").deepSerialize(collection);
    }

	public static Collection<SystemMailMessage> fromJsonArrayToSystemMailMessages(String json) {
        return new JSONDeserializer<List<SystemMailMessage>>().use(null, ArrayList.class).use("values", SystemMailMessage.class).deserialize(json);
    }

	public String toString() {
        return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }

	public String getSubject() {
        return this.subject;
    }

	public void setSubject(String subject) {
        this.subject = subject;
    }

	public String getBody() {
        return this.body;
    }

	public void setBody(String body) {
        this.body = body;
    }

	public String getMessageType() {
        return this.messageType;
    }

	public void setMessageType(String messageType) {
        this.messageType = messageType;
    }

	public Person getSender() {
        return this.sender;
    }

	public void setSender(Person sender) {
        this.sender = sender;
    }

	public String getRecipientTo() {
        return this.recipientTo;
    }

	public void setRecipientTo(String recipientTo) {
        this.recipientTo = recipientTo;
    }

	public String getRecipientCC() {
        return this.recipientCC;
    }

	public void setRecipientCC(String recipientCC) {
        this.recipientCC = recipientCC;
    }

	
	public Long getId() {
	    return this.id;
	}

	public void setId(Long id) {
	    this.id = id;
	}


	private static final long serialVersionUID = 1L;
}
